﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using HNQXYJ.Model;
namespace HNQXYJ.BLL
{
    /// <summary>
    /// City 的摘要说明
    /// </summary>
    public class City : IHttpHandler, IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            int id=Convert.ToInt32(context.Request["id"]);
            //获取城市名称
            if (action == "GetCityLists")
            {
                CityBLL cb = new CityBLL();
                List<HCity> list = new List<HCity>();
                list = cb.GetCityListAll();
                int count = list.Count;
                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(list));
            }
            //获取一个城市的信息
            if (action == "GetOneCity")
            {
                string selfCode =context.Session["ranklevel"].ToString();
                if (selfCode.Length > 3)
                {
                    selfCode = selfCode.Substring(0, 3);
                }
                HCity city = new CityBLL().GetCityBySelfCode(selfCode);
                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(city));
 
            }
           // context.Response.Write("Hello World");

            if (id >0)
            {
                int res = new CityBLL().DeleteCityById(id);
                if (res > 0)
                {
                    context.Response.Redirect("../HN_City/CityMgr.aspx");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}